package org.dllwh.milvus.model;

import lombok.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 把今天最好的表现当作明天最新的起点．．～
 * <p>
 * Today the best performance as tomorrow the newest starter!
 *
 * @ClassName AjaxResult
 * @Description 统一返回值格式
 * @Author: <a href="mailto:duleilewuhen@sina.com">独泪了无痕</a>
 * @Date 2025-05-24 01:01
 * @版本 V 1.0.1
 * @since JDK 17
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = true)
public class AjaxResult extends HashMap<String, Object> {
    // 响应状态码
    private Integer code;
    // 提示信息
    private String msg;
    // 响应数据
    private Object data;

    public AjaxResult(Integer code, String message) {
        super();
        this.code = code;
        this.msg = message;
    }

    public AjaxResult(int code, String msg, Object data) {
        super();
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static AjaxResult success() {
        return new AjaxResult(200, "操作成功");
    }

    public static AjaxResult success(String message) {
        return new AjaxResult(200, message);
    }

    public static AjaxResult success(Object data) {
        return new AjaxResult(200, "操作成功", data);
    }

    public static AjaxResult fail() {
        return new AjaxResult(201, "操作失败");
    }

    public static AjaxResult fail(int resultCode, String message) {
        return new AjaxResult(resultCode, message);
    }

    public static AjaxResult fail(int resultCode, String msg, Object data) {
        return new AjaxResult(resultCode, msg, data);
    }

    /**
     * 其他标识符（服务器当前时间、访问url、错误类型、错误的堆栈轨迹）
     */
    @Override
    public AjaxResult put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
